package com.android.monee.data.access.inMemory;

import java.util.ArrayList;
import java.util.List;

import com.android.monee.data.access.MensualityDao;
import com.android.monee.data.model.Budget;
import com.android.monee.data.model.Mensuality;
import com.android.monee.data.model.Mensuality.MensualityState;

public class MensualityDaoInMemory extends AbstractDaoInMemory<Mensuality, Integer> implements MensualityDao{

	private static MensualityDaoInMemory instance;
	
	public static MensualityDaoInMemory getInstance(){
		if(instance == null)
			instance = new MensualityDaoInMemory();
		return instance;
	}
	
	private MensualityDaoInMemory(){
		super();
		//TODO : appeler ceci dans la factory et mettre dans fonction init();
//		BudgetDao budgetDao = DaoFactory.getBudgetDao();
//		
//		for(Budget budget : budgetDao.findAll()){
//			for(Mensuality mens : InMemoryMockDatas.getMockMensualityDoneList(budget)){
//				super.insert(mens);
//			}
//		}
	}
	
	@Override
	protected Integer getNextId() {
		Integer id = DaoUtils.getNextId(super.datas.values()); 
		return id;
	}

	public List<Mensuality> findByBudget(Budget budget){
		List<Mensuality> res = new ArrayList<Mensuality>();
		
		for(Mensuality mens : super.datas.values()){
			if(mens.getBudgetId().equals(budget.getId()))
				res.add(mens);
		}
		return res;
	}

	@Override
	public List<Mensuality> findByBudgetAndState(Budget budget,
			MensualityState state) {
		List<Mensuality> res = new ArrayList<Mensuality>();
		
		for(Mensuality mens : super.datas.values()){
			if(mens.getBudgetId().equals(budget.getId()) 
					&& mens.getState().equals(state))
				res.add(mens);
		}
		return res;
	}
	
}
